<template>
  <el-form label-position="right" label-width="100px">
    <el-form-item label="部门名称">
        <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="部门编码">
        <el-input v-model="form.code"></el-input>
    </el-form-item>
    <el-form-item label="部门负责人">
        <el-select v-model="form.manager">
            <el-option v-for="item in list" :key="item.id" :value="item.username" :label="item.username"></el-option>
        </el-select>
    </el-form-item>
    <el-form-item label="部门介绍">
        <el-input v-model="form.introduce"></el-input>
    </el-form-item>
    <template class="btn">
        <el-button type="primary" @click.native="doSubmit">确定</el-button>
        <el-button>取消</el-button>
    </template>
  </el-form>
</template>
<script>
import {getEmployee,addDepartments} from '@/api/departments'
export default {
    name:'departmentsDialog',
    props:{
        pid:{
            required:true,
            type:String
        }
    },
    data() {
        return {
            //表单数据
            form:{
                name:'',
                code:'',
                manager:'',
                introduce:'',
            },
            //简单员工信息
            list:[]
        };
    },
    async created(){
        //获取管理人员信息
        const {data:res}=await getEmployee()
        console.log('简单员工信息',res);
        this.list=res.data
    },methods:{
        //提交表单信息
       async doSubmit(){
          const {data:res} =await addDepartments({...this.form,pid:this.pid})
        //   console.log('新增部门',res);
        if(res.code===10000){
            this.$message.success(res.message)
            this.$emit('success')
        }
        }
    }
}
</script>

<style>

</style>